﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CH.Easy.DbProvider.Core;
using CH.Easy.DbProvider.Common;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Activation;
using System.Reflection;
using CH.Easy.DbProvider.Entity;
using System.Diagnostics;
using System.Data;
using System.Data.OleDb;
using CH.Easy.DbProvider.Interface;
namespace CH.Easy.DbProvider.Test
{











    class Program
    {
        static void Main(string[] args)
        {

            CHEasyCMS cms = new CHEasyCMS();

          


            var result = cms.TSQLEngine.ExecuteSQL("select * from member", ExecuteType.ExecuteDataTable);
            DataTable dt = result as DataTable;
            List<Member> list = dt.ToList<Member>();

            //OleDbType
            //SqlDbType
            //DbType
            //TypeCode
            int index = 1;
            int size = 100;


            Specification<Member> s = new Specification<Member>();
            s.And(p => p.ID > 100);
            s.And(p => p.ID < 200);
            s.And(p => p.ID.In(new int[] { 111, 200, 311 }));
            var result1 = cms.Member.Count(p => p.ID > 100);
            var result2 = cms.Member.Where(p => p.Name.Like("f%")).Count();
            var result3 = cms.Member.Where(p => p.Name.Like("f%")).Count(p => p.ID > 100);

            var result4 = cms.Member.Sum(p => (long)p.ID);
            var result5 = cms.Member.Where(p => p.Name.Like("f%")).Sum(p => (long)p.ID);


            var result6 = cms.Member.Max(p => (long)p.ID);
            var result7 = cms.Member.Where(p => p.Name.Like("f%")).Max(p => (long)p.ID);

            var result8 = cms.Member.Min(p => p.ID);
            var result9 = cms.Member.Where(p => p.Name.Like("f%")).Min(p => p.ID);

            var result10 = cms.Member.Average(p => p.Age);
            var result11 = cms.Member.Where(p => p.Name.Like("f%")).Average(p => p.ID);
            var list12 = cms.Member.Where(p => p.Name.Like("f%")).Select(p => new { id = p.ID, name = p.Name }).Where(p => p.name.Like("f%")).Select(p => p.id).ToList();
            var list13 = cms.Member.Where(p => p.Name.Like("f%")).Select(p => p).ToList();
            var list14 = cms.Member.Where(p => p.Name.Like("f%")).OrderByDescending(p => p.ID).Select(p => new { id = p.ID, name = p.Name }).ToList();
            var list15 = cms.Member.Where(p => p.Name.Like("f%")).OrderByDescending(p => p.ID).Select(p => new Member { ID = p.ID, Name = p.Name }).ToList();

            var list16 = cms.Member.Where(p => p.Name.Like("f%")).Skip((index - 1) * size).Take(size).OrderByDescending(p => p.ID).Select(p => new Member { ID = p.ID, Name = p.Name }).ToPList();

            var list17 = cms.Member.Where(p => p.Name.Like("f%")).OrderByDescending(p => p.ID.As("MaxID")).GroupBy(p => new Member { Name = p.Name }).Select(p => new { ids = p.Key.ID.Count().As("MaxID"), names = p.Key.Name }).ToList();

            var list18 = cms.Member.Where(p => p.ID > 10).Join(cms.Photo, p => p.ID, p => p.MemberID, (m, p) => new { MemberID = p.MemberID, Name = m.Name, Age = m.Age }).ToList();
            var list19 = cms.Member.Where(s.Sp).Skip((index - 1) * size).Take(size).Join(cms.Photo, p => p.ID, p => p.MemberID, (m, p) => new { PID = p.ID, MemberID = p.MemberID, Name = m.Name });
            var list20 = cms.Member.Where(s.Sp).Skip((index - 1) * size).Take(size).Join(cms.Photo, p => p.ID, p => p.MemberID, (m, p) => new { PID = p.ID, Url = p.Url, Title = p.Title, Age = m.Age, Desc = p.Desc, AddTime = m.AddTime, MemberID = p.MemberID, Name = m.Name }).ToPList();


            Member member = new Member();
            member.AddTime = DateTime.Now;
            member.Age = 0;
            member.Email = "fdsa@fdsa.com";
            member.Name = "test";
            member.Level = 100;
            var result21 = cms.Member.Add(member);

            member.Level = 500;

            var result22 = cms.Member.Modify(member, p => p.ID == member.ID && p.Name == member.Name, "Level");



            var result23 = cms.Member.Remove(p => p.ID == member.ID);
            var result24 = cms.Member.Remove(p => p.ID == 406);

           Console.Read();











            //TestEntity te = new TestEntity();

            //foreach (var item in te.ChangedProperties)
            //{
            //    Console.WriteLine(item.Key + "===" + item.Value);
            //}



            //Stopwatch s = new Stopwatch();
            //s.Start();
            //TestEntity te = new TestEntity();
            //for (int i = 0; i < 10000; i++)
            //{
            //    te.ID = i;
            //}

            //s.Stop();
            //long result1 = s.ElapsedTicks;
            //Console.WriteLine(result1);
            //s.Reset();
            //s.Start();

            //TestEntity2 te2 = new TestEntity2();
            //for (int i = 0; i < 10000; i++)
            //{

            //    te2.ID = i;
            //}
            //s.Stop();
            //long result2= s.ElapsedTicks;
            //Console.WriteLine(result2);

            //Console.WriteLine(result1/result2);










            //QHome home = new QHome();
            //var list = home.Member.Where(p => p.ID > 100).Select(p => new { id = p.ID, name = p.Name });


            Console.Read();
        }
    }
}
